package junmo.s3caesar.mandu.nhkradionews.activity;

import java.util.List;

import junmo.s3caesar.mandu.nhkradionews.R;
import junmo.s3caesar.mandu.nhkradionews.data.News;
import junmo.s3caesar.mandu.nhkradionews.data.NewsAdapter;
import junmo.s3caesar.mandu.nhkradionews.data.NewsFinder;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;

public class NewsListActivity extends ListActivity {
	
	private ProgressDialog progressDialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.news_list_activity);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		progressDialog = ProgressDialog.show(this, "", "少々お待ちください。", true, false);
		new FindNewsList().execute((Void) null);
	}

//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.main, menu);
//		return true;
//	}
	
	private class FindNewsList extends AsyncTask<Void, Void, List<News>> {
		
		@Override
		protected List<News> doInBackground(Void... params) {
			return new NewsFinder("http://www.nhk.or.jp/r-news/podcast/nhkradionews.xml").findNewsList();
		}
		
		@Override
		protected void onPostExecute(List<News> result) {
			progressDialog.dismiss();
			NewsAdapter newsAdapter = new NewsAdapter(getApplicationContext(), result);
			setListAdapter(newsAdapter);
		}
		
	}
	
}
